
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: AbstractDatabaseUpdate.java 90 2009-04-23 03:07:07Z archie.cobbs $
 */

package org.dellroad.sidekar.schema;

import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;

/**
 * Support superclass for {@link DatabaseUpdate} implementations.
 *
 * <p>
 * User subclasses of this class can only modify database content, not structure.
 * For structural schema changes, utilize one of the pre-defined schema modification classes.
 */
public abstract class AbstractDatabaseUpdate implements DatabaseUpdate {

    protected final Logger log = Logger.getLogger(getClass());

    private final String name;

    private Set<String> requiredPredecessors = new HashSet<String>();

    /**
     * Constructor.
     *
     * @param name unique name for this update
     * @throws IllegalArgumentException if name is null or the empty string
     */
    protected AbstractDatabaseUpdate(String name) {
        if (name == null)
            throw new IllegalArgumentException("invalid null update name");
        if (name.length() == 0)
            throw new IllegalArgumentException("invalid empty update name");
        this.name = name;
    }

    public final String getName() {
        return this.name;
    }

    public Set<String> getRequiredPredecessors() {
        return this.requiredPredecessors;
    }

    public void setRequiredPredecessors(Set<String> requiredPredecessors) {
        this.requiredPredecessors = requiredPredecessors;
    }

    /**
     * This implementation returns this update's name.
     */
    @Override
    public String toString() {
        return this.name;
    }
}

